home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / progut~1 / iostream.zoo / test / t.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-22  |  829 b   |  42 lines

  1. #include <iostream.h>
  2. #include <assert.h>
  3. #include <stdio.h>
  4.  
  5. main ()
  6. {
  7.   char ch;
  8.   int i;
  9.   
  10.   cout << "\nMaking filebuf streams fout and fin...";
  11.   filebuf foutbuf;
  12.   foutbuf.open("ffile", ios::out);
  13.   ostream fout(&foutbuf);
  14.   assert(fout.good());
  15.   assert(fout.is_open());
  16.   assert(fout.writable());
  17.   assert(!fout.readable());
  18.   fout << "This file has one line testing output streams.\n";
  19.   fout.close();
  20.   assert(!fout.is_open());
  21.   filebuf finbuf;
  22.   finbuf.open("ffile", ios::in);
  23.   istream fin(&finbuf);
  24.   assert(fin.good());
  25.   assert(fin.is_open());
  26.   assert(!fin.writable());
  27.   assert(fin.readable());
  28.   cout << "contents of file:\n";
  29.  
  30.   do
  31.   {
  32.       i = ((fin >> ch) ? 1 : 0);
  33.       fprintf(stderr, "i is %d\n", i);
  34.       if(!i)
  35.       break;
  36.       cout << ch;
  37.   } while(1);
  38.   
  39.   fin.close();
  40.   assert(!fin.is_open());
  41. }
  42.